package com.gfxy.modules.index.service;

import com.alibaba.fastjson.JSONObject;
import com.gfxy.modules.index.mapper.ResearchdexMapper;
import com.gfxy.modules.classtime.entity.ClasstimeScore;
import com.gfxy.modules.classtime.mapper.ClasstimeScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Description: TODO
 * @author: scott
 * @date: 2021年11月10日 13:41
 */
@Service
public class ResarchIndexService {

    @Autowired
    private ResearchdexMapper researchdexMapper;

    @Autowired
    private ClasstimeScoreMapper classtimeScoreMapper;



    public ClasstimeScore getClasstimeReportCurrentDateByUsername(String username) {
        return classtimeScoreMapper.getClasstimeReportCurrentDateByUsername(username);
    }

    public JSONObject getTeacherTeachingBuildResult(String username, String date){
        Map orgResult = this.researchdexMapper.getTeacherOrgTeachingRankd(username,date);
        Map schoolResult = this.researchdexMapper.getTeacherSchoolTeachingRankd(username,date);
        int schoolNum = this.getSchoolTotalPeopleNum();
        int orgNum = this.getOrgTotalPeopleNum(username);

        System.out.println(orgResult);
        System.out.println(schoolResult);

        JSONObject result = new JSONObject();
        result.put("totalScore",Double.parseDouble(String.valueOf(orgResult.get("score"))));
        result.put("orgRankd",Integer.parseInt(String.valueOf(orgResult.get("rankd"))));
        result.put("schoolRankd",Integer.parseInt(String.valueOf(schoolResult.get("rankd"))));
        result.put("schoolNum",schoolNum);
        result.put("orgNum",orgNum);
        return result;
    }

    public int getSchoolTotalPeopleNum(){
        Map result = this.researchdexMapper.getSchoolTotalPeopleNum();
        return Integer.parseInt(String.valueOf(result.get("people_num")));
    }

    public int getOrgTotalPeopleNum(String username){
        Map result = this.researchdexMapper.getOrgTotalPeopleNum(username);
        return Integer.parseInt(String.valueOf(result.get("people_num")));
    }

    public JSONObject getTeacherCount(String username) {
        JSONObject result = new JSONObject();
        result.put("schoolTeacherCount",this.getSchoolTotalPeopleNum());
        result.put("orgTeacherCount",this.getOrgTotalPeopleNum(username));
        return result;
    }
}
